package com.jiangnan.ui.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter4.BaseQuickAdapter
import com.jiangnan.databinding.ItemUserBorrowListBinding
import com.jiangnan.entity.UserBorrowBookInfo
import com.jiangnan.ui.adapter.RepositoryQuickAdapter.VH
import com.jiangnan.util.GlideUtil

class UserBorrowBookInfoQuickAdapter : BaseQuickAdapter<UserBorrowBookInfo, UserBorrowBookInfoQuickAdapter.VH>() {
    class VH(
        parent: ViewGroup,
        val binding: ItemUserBorrowListBinding = ItemUserBorrowListBinding.inflate(
            LayoutInflater.from(parent.context), parent, false
        ),
    ) : RecyclerView.ViewHolder(binding.root)

    override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
        // 返回一个 ViewHolder
        return VH(parent)
    }

    override fun onBindViewHolder(holder: VH, position: Int, item: UserBorrowBookInfo?) {
        // 设置item数据
        holder.binding.let {
            it.tvNickname.text = item?.nickname
            it.tvPhone.text = item?.phone
            when (item?.status) {
                0 -> {
                    it.statusBlocked.isChecked = true
                }
                1 -> {
                    it.statusActive.isChecked = true
                }
            }
            it.tvBorrowBookNum.text = "正在借阅书籍 "+item?.borrowBookNum.toString()+" 本"
            GlideUtil.loadImageWithPlaceholder(
                holder.itemView.context,
                item?.avatar ?: "",
                com.jiangnan.R.drawable.img_default,
                com.jiangnan.R.drawable.img_error,
                it.ivAvatar
            )
        }
    }
}